*--------------------------------------------------------------; * Estimate of the population mean or total for a two-stage ; * cluster sample, in which clusters are selected (with ; * replacement) with probability proportional to size of ; * cluster. ; *--------------------------------------------------------------; %macro est_cl2p(sample=,setup=,m=,cluster=,response=,ybar=, phat=,totals=,mi=,param=,rep=,npop=); %if %length(&sample) = 0 %then %let sample = %str(sample); %if %length(&cluster) = 0 %then %let cluster = %str(cluster); %if %length(&rep) > 0 %then %let strep = %str( &cluster &rep ); %else %let strep = %str( &cluster ); proc sort data = &sample; by &strep ; %if %length(&response) > 0 %then %do; %let strng = %str(Response Variable = &response); proc means data = &sample noprint; by &strep ; var &response; output out = means_ mean = ybari_; %end; %if %length(&phat) > 0 %then %do; %let strng = %str(Response Variable (Proportions) = &phat); data means_; set &sample; ybari_ = &phat; %end; %if %length(&ybar) > 0 %then %do; %let strng = %str(Response Variable (Means) = &ybar); data means_; set &sample; ybari_ = &ybar; %end; %if %length(&totals) > 0 %then %do; %let strng = %str(Response Variable (Totals) = &totals); data means_; set &sample; ybari_ = &totals/&mi; %end; proc means data = means_ noprint; var ybari_; output out = new_ mean = ybar_ var = s2_ n=n_; data est_; %if %length(&setup) > 0 %then %do; merge &setup new_; %end; %else %do; set new_; %end; mu_hat_ = ybar_; var_mu_ = s2_/n_; std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; %if %length(&m) > 0 %then %do; tau_hat_ = &m*ybar_; std_tau_ = &m*std_mu_; bnd_tau_ = &m*bnd_mu_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Estimate of Population Mean'; title2 'Two-stage Cluster Sample'; title3 'Clusters Selected by PPS Design'; title4 "&strng"; label mu_hat_ = 'estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; label s2_ = 's^2'; var mu_hat_ std_mu_ bnd_mu_ s2_; %end; %if %index(%upcase(¶m),PROP) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Estimate of Population Proportion'; title2 'Two-stage Cluster Sample'; title3 'Clusters Selected Proportional to Size'; title4 "&strng"; label mu_hat_ = 'estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; label s2_ = 's^2'; var mu_hat_ std_mu_ bnd_mu_ s2_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Estimate of Population Total'; title2 'Two-stage Cluster Sample'; title3 'Clusters Selected Proportional to Size'; title4 "&strng"; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; label s2_ = 's^2'; var tau_hat_ std_tau_ bnd_tau_ s2_; %end; run; title; %mend est_cl2p;